package com.lcxw.hxzbadmin.controller.membercontroller;

import com.lcxw.hxzbadmin.entity.requestbean.DealRealNameAuthReq;
import com.lcxw.hxzbadmin.entity.requestbean.GetRealNameAuthReq;
import com.lcxw.hxzbapi.controller.membercontroller.MemberRealization;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.RealNameAuthService;
import com.lcxw.hxzbcommon.entity.ErrorCode;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/user/realNameAuth")
@Slf4j
public class RealNameAuthController {

    @Resource
    MemberRealization memberRealization;


    /**
     * 获取实名认证人员名单
     */
    @PostMapping("/list/get")
    public Response getRealNameAutList(@RequestBody GetRealNameAuthReq getRealNameAuthReq) {
        String status = getRealNameAuthReq.getStatus();
        int pageNum = getRealNameAuthReq.getPageNum();
        int pageSize = getRealNameAuthReq.getPageSize();

        return memberRealization.getRealNameAuthList(status, pageNum, pageSize);
    }

    /**
     * 处理实名认证接口
     */
    @PostMapping("/deal")
    public Response dealRealNameAuth(@RequestBody DealRealNameAuthReq dealRealNameAuthReq) {
        int id = dealRealNameAuthReq.getId();
        String status = dealRealNameAuthReq.getStatus();
        String adminName = dealRealNameAuthReq.getAdminName();
        String reason = dealRealNameAuthReq.getReason();

        if (status.equals("认证未通过") && reason == null) {
            return Response.error(ErrorCode.INVALID_PARAM, "认证未通过时，必须填写原因");
        }
        try {
            return memberRealization.dealRealNameAuth(id, status, reason, adminName);
        } catch (Exception e) {
            return Response.dbFail(log, "更新用户实名认证");
        }
    }
}
